import { PartcustomerDataApi } from '@/services/database'
import {ref,onMounted} from 'vue'
import type {Ref} from 'vue'

//用户列表数据
export const tableDataList = (pageNum = 1,query={}): [Ref<any>,Ref<any>, Ref<number>, (page?: number,query?:object) => Promise<void>] => {
    const data = ref<any>()
    const dat2 = ref<any>()
    
    // const total = ref<UserModule.IUserList['total']>(0)
    const total = ref(0)
   
  
    const loadData=async (page=1,query : object ={})=>{
      let ret = await PartcustomerDataApi(page,query)
      if(ret.code===200){
       
       
        data.value = ret.data.data1
        dat2.value = ret.data.data2
        total.value = 100
       
        
      }
      
    }
    
    onMounted(()=>{
      loadData(pageNum,query)
    })
    return[data,dat2,total,loadData]
  }
  //深复制
  export const  deepClone=<T>(obj: T): T=> {
    if (obj === null || typeof obj !== 'object') {
      return obj;
    }
  
    let clone: any;
    if (Array.isArray(obj)) {
      clone = [];
      for (let i = 0; i < obj.length; i++) {
        clone[i] = deepClone(obj[i]);
      }
    } else {
      clone = {};
      for (let key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          clone[key] = deepClone(obj[key]);
        }
      }
    }
  
    return clone;
  }
